/*
 * Project it.battlehorse.rcp.tools
 * Created on Nov 18, 2005
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */
package it.battlehorse.rcp.tools.views.actorlist;

import it.battlehorse.rcp.sl.annot.Injected;
import it.battlehorse.rcp.sl.annot.Serviceable;
import it.battlehorse.rcp.tools.actors.ActorDescriptor;
import it.battlehorse.rcp.tools.actors.IActorRegistry;

import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 * Defines the content provider for the Actors list view
 * 
 * @author battlehorse
 * @since Nov 18, 2005
 */
@Serviceable
public class ActorListContentProvider implements IStructuredContentProvider {
	
	List<ActorDescriptor> contents;
	
	/* A reference to an actor registry */
	private IActorRegistry registry;
	
	/**
	 * Injects a reference to a valid actor registry
	 * 
	 * @param registry a reference to a valid actor registry
	 */
	@Injected
	public void setActorRegistry(IActorRegistry registry) {
		this.registry = registry;
	}
	
	/**
	 * Creates a new instance of the class
	 *
	 */
	public ActorListContentProvider() {
		
		// Retrieves only the visible actors
		contents = registry.getKnownActorConfiguration(true);    	
	}
	
	public ActorListContentProvider(List<ActorDescriptor> contents) {
		
		this.contents = contents;
	}
	

	public void inputChanged(Viewer v, Object oldInput, Object newInput) {
		// Ignore
	}
    
    public void dispose() {
    	// nothing to dispose
    }
    
    public Object[] getElements(Object parent) {           	
    	return contents.toArray();
    }
}